/**
 ****************************************************************************************
 *
 * @file blelib.h
 *
 * @brief BLE Lib Definitions.
 *
 ****************************************************************************************
 */

#ifndef _BLELIB_H_
#define _BLELIB_H_

/// struct *_env_tag *_env
#define __VAR_ENV               __attribute__((section("le_env_mem_area"), zero_init))

/// define the BLE Task handler attribute for this compiler
#define __TASKFN                __attribute__((section("le_task_hdl_func")))

#if defined(CONFIG_PORT_BLE_CAPABILITY_1C_M_S)

#define BLE_CONNECTION_MAX      (1)     /*!< 最大连接数 (同时): 1 ，主/从，支持超低功耗 (ultra low power) */
#define BLE_ACTIVITY_MAX        (2)     /*!< 最大活动数 (同时): 2 ，1 广播、1 连接 (dotc:这个有点像连接状态 (LE Link Layer States) ) */

/**
 * @brief 
 *  蓝牙协议堆  (BLE Heap) 使用情况 (MEM_ENV + MEM_MSG) - 在保留内存区域
 *  Heap usage for BLE Stack (MEM_ENV + MEM_MSG) - at Retention Memory Area
 * @note SRAM2 蓝牙协议堆 (BLE Heap)
 */
#define BLE_HEAP_BASE           (0x20006200)
#define BLE_HEAP_ENV_SIZE       (0xC00)
#define BLE_HEAP_MSG_SIZE       (0xC00)
#define BLE_HEAP_SIZE           (BLE_HEAP_ENV_SIZE + BLE_HEAP_MSG_SIZE)
#define BLE_HEAP_END            (BLE_HEAP_BASE + BLE_HEAP_SIZE)

/**
 * @brief 
 *  BLE 硬件交换的内存使用 -在保留内存区域
 *  Memory usage for BLE HW Exchange - at Retention Memory Area
 * @note SRAM2 蓝牙硬件与软件交换区 (BLE HW Exchange)
 */
#define BLE_EXCH_BASE           (0x20008000)
#define BLE_EXCH_SIZE           (0x0FD8)
#define BLE_EXCH_END            (BLE_EXCH_BASE + BLE_EXCH_SIZE)

/**
 * @brief
 *  *.lib 的内存区域 (+RW +ZI) - 在保留内存区域
 *  *.lib (+RW +ZI) - at Retention Memory Area
 * @note SRAM2 中的保留区域 (Retention)
 */
#define BLE_RWZI_BASE           (BLE_EXCH_END)
#define BLE_RWZI_END            (0x2000A000)
#define BLE_RWZI_SIZE           (BLE_RWZI_END - BLE_RWZI_BASE)

#elif defined(CONFIG_PORT_BLE_CAPABILITY_3C_M_S)

#define BLE_CONNECTION_MAX      (3)     /*!< 最大连接数 (同时): 3 ，主/从 */
#define BLE_ACTIVITY_MAX        (4)     /*!< 最大活动数 (同时): 4 ，广播、扫描、发起连接(Initiating) 、连接 (dotc:这个有点像连接状态 (LE Link Layer States) ) */

/**
 * @brief 
 *  蓝牙协议堆  (BLE Heap) 使用情况 (MEM_ENV + MEM_MSG) - 在保留内存区域
 *  Heap usage for BLE Stack (MEM_ENV + MEM_MSG) - at Retention Memory Area
 * @note SRAM2 蓝牙协议堆 (BLE Heap)
 */
#define BLE_HEAP_BASE           (0x20004E00)
#define BLE_HEAP_ENV_SIZE       (0xC00)
#define BLE_HEAP_MSG_SIZE       (0x2000)
#define BLE_HEAP_SIZE           (BLE_HEAP_ENV_SIZE + BLE_HEAP_MSG_SIZE)
#define BLE_HEAP_END            (BLE_HEAP_BASE + BLE_HEAP_SIZE)

/**
 * @brief 
 *  BLE 硬件交换的内存使用 -在保留内存区域
 *  Memory usage for BLE HW Exchange - at Retention Memory Area
 * @note SRAM2 蓝牙硬件与软件交换区 (BLE HW Exchange)
 */
#define BLE_EXCH_BASE           (0x20008000)
#define BLE_EXCH_SIZE           (0x0FD8)
#define BLE_EXCH_END            (BLE_EXCH_BASE + BLE_EXCH_SIZE)

/**
 * @brief
 *  *.lib 的内存区域 (+RW +ZI) - 在保留内存区域
 *  *.lib (+RW +ZI) - at Retention Memory Area
 * @note SRAM2 中的保留区域 (Retention)
 */
#define BLE_RWZI_BASE           (BLE_EXCH_END)
#define BLE_RWZI_END            (0x2000A000)
#define BLE_RWZI_SIZE           (BLE_RWZI_END - BLE_RWZI_BASE)

#elif defined(CONFIG_PORT_BLE_CAPABILITY_1C_S)

#define BLE_CONNECTION_MAX      (1)     /*!< 最大连接数 (同时): 1 ，仅从 */
#define BLE_ACTIVITY_MAX        (2)     /*!< 最大活动数 (同时): 2 ，1 广播、1 连接 (dotc:这个有点像连接状态 (LE Link Layer States) ) */

/**
 * @brief 
 *  蓝牙协议堆  (BLE Heap) 使用情况 (MEM_ENV + MEM_MSG) - 在保留内存区域
 *  Heap usage for BLE Stack (MEM_ENV + MEM_MSG) - at Retention Memory Area
 * @note SRAM2 蓝牙协议堆 (BLE Heap)
 */
#define BLE_HEAP_BASE           (0x20008BAC)
#define BLE_HEAP_ENV_SIZE       (0x600)
#define BLE_HEAP_MSG_SIZE       (0x600)
#define BLE_HEAP_SIZE           (BLE_HEAP_ENV_SIZE + BLE_HEAP_MSG_SIZE)
#define BLE_HEAP_END            (BLE_HEAP_BASE + BLE_HEAP_SIZE)

/**
 * @brief 
 *  BLE 硬件交换的内存使用 -在保留内存区域
 *  Memory usage for BLE HW Exchange - at Retention Memory Area
 * @note SRAM2 蓝牙硬件与软件交换区 (BLE HW Exchange)
 */
#define BLE_EXCH_BASE           (0x20008000)
#define BLE_EXCH_SIZE           (0x0BAC)
#define BLE_EXCH_END            (BLE_EXCH_BASE + BLE_EXCH_SIZE)

/**
 * @brief
 *  *.lib 的内存区域 (+RW +ZI) - 在保留内存区域
 *  *.lib (+RW +ZI) - at Retention Memory Area
 * @note SRAM2 中的保留区域 (Retention)
 */
#define BLE_RWZI_BASE           (BLE_HEAP_END)
#define BLE_RWZI_END            (0x2000A000)
#define BLE_RWZI_SIZE           (BLE_RWZI_END - BLE_RWZI_BASE)

#endif

#endif /* _BLELIB_H_ */
